package com.suypower.carManage.json;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import java.util.Vector;

/**
 * Created by zhaoyuan on 14-2-17.
 */
public class Get_User_List extends ActionSupport{

    private String name;
    private String username;
    private String code;
    DAO dao=new DAO();

    public String execute(){
        String res="";
        String sql="SELECT * FROM tb_user WHERE 1=1 ";
        if(name!=null&&!name.equals("")){
            sql+=" AND name LIKE '%"+name+"%' ";
        }
        if(username!=null&&!username.equals("")){
            sql+=" AND userName LIKE '%"+username+"%' ";
        }
        try {
            Vector v=dao.getDataSet(ConstUtil.DBNAME,sql);
            if(v!=null){
                JSONArray json=JSONArray.fromObject(v);
                res=json.toString();
            }
        } catch (ServletException e) {
            e.printStackTrace();
        }
        ActionContext.getContext().put("data", res);
        return SUCCESS;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
